/*
 * Adam Blackwell ada2358@ccs.neu.edu
 */
/**
 * Coord :
 * 
 * @author Adam
 */
class Coord {
  private int x;
  private int y;
  
  // Creates a new coordinate if x and y are non-negative, throws
  // error otherwise.
  private Coord(int x, int y) {
    if (x < 0 || y < 0) {
      throw new IllegalArgumentException("xPos and yPos must be positive.");
    }
    this.x = x;
    this.y = y;
  }
  
  // Creates a new coordinate if x and y are non-negative, throws
  // error otherwise.
  public static Coord create(int x, int y) {
    return new Coord(x, y);
  }
  
  // Extracts x coordinate from this coordinate.
  public int xPos() {
    return this.x;
  }
  
  // Extracts y coordinate from this coordinate.
  public int yPos() {
    return this.y;
  }
  
  // Creates a new coordinate from this coordinate using the given x
  // and y offset.
  public Coord move(int dx, int dy) {
    return Coord.create(x + dx, y + dy);
  }
  
  // Creates a new coordinate from this coordinate using
  // the position of the given coordinate as an offset.
  public Coord add(Coord c) {
    return Coord.create(x + c.xPos(), y + c.yPos());
  }
  
  // Checks whether this coordinate is within the
  // bounds of the two given coordinates.
  public boolean within(Coord c1, Coord c2) {
    return (c1.xPos() <= this.xPos()) && (this.xPos() <= c2.xPos())
           && (c1.yPos() <= this.yPos()) && (this.yPos() <= c2.yPos());
  }
  
  // Checks to see if this coordinate has the same
  // field values as the given coordinate.
  public boolean equals(Coord c) {
    return (this.xPos() == c.xPos()) && (this.yPos() == c.yPos());
  }
  
  // Returns false for every input because the equals method that is
  // more specific
  // for the input of Coord takes precedence.
  public boolean equals(Object obj) {
    return false;
  }
  
  // Returns the hashcode for this coordinate using the cantor pairing
  // function.
  public int hashCode() {
    return (this.xPos() + this.yPos()) * (this.xPos() + this.yPos() + 1) / 2
           + this.yPos();
  }
  
  // Returns a string of this coordinate using the fields of this
  // coordinate
  public String toString() {
    return "(" + x + "," + y + ")";
  }
}
/*
 * 2a) public int distance(Coord); 2b)
 * Coord.create(x,y).distance(Coord.create(a,b)) =/sqrt { (y-b)^2 +
 * (x-a)^2 } public double distance(Coord c){ return
 * Math.sqrt(Math.pow( ( c.yPos() - this.yPos() ), 2) + Math.pow( (
 * c.xPos() - this.xPos() ), 2)); } 3a) Coord.origin().xPos() = 0
 * Coord.origin().yPos() = 0 Coord.origin().move(dx,dy) =
 * Coord.create(dx,dy) Coord.origin().add(c) =
 * Coord.create(c.xPos(),c.yPos()) Coord.origin().within(c1,c2) = true
 * if c1.xPos() <= 0 <= c2.xPos() and c1.yPos() <= 0 <= c2.yPos() =
 * false otherwise Coord.origin().equals(c) = true if c.xPos() = 0 and
 * c.yPos() = 0 = false otherwise Coord.origin().equals(obj) = false
 * Coord.create(x,y).hashCode() = (x+y)*(x+y+1)/2 + y
 * Coord.create(x,y).toString() = "(" + x + "," + y + ")" 3b)
 * Coord.origin() = Coord.create(0,0)
 */
